package com.molin.annoTest.lianxi;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Demo {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
//1.获取类中的方法中使用了Test注解
        Class clazz=Class.forName("com.molin.annoTest.lianxi.UserTest");
        Method[] methods = clazz.getMethods();
        Constructor constructor = clazz.getConstructor();
        UserTest userTest= (UserTest) constructor.newInstance();
//2.判断，如果使用了Test注解就必须执行
        Class testClass=Class.forName("com.molin.annoTest.lianxi.Test");
        for (Method method : methods) {
            if(method.isAnnotationPresent(testClass)){
                method.invoke(userTest);
            }
        }
    }
}
